package graphics.raytracing;

import graphics.rasterizing.camera.CameraPosition;
import static util.MatrixOperationsF.*;
public class Window {
	private LightSource _source;
	private int _ymax;
	private int _xmax;
	public Window(float[] origin,float[] vx,float[] vy,int xmax,int ymax,LightSource source)
	{
		_o=cloo(origin);
		_vx=cloo(vx);
		_vy=cloo(vy);
		content = new float[xmax][ymax][];
		_source=source;
		_xmax = xmax;
		_ymax = ymax;
	}
	private float[] _o;//topleft
	private float[] _vx;//vector to the right
	private float[] _vy;//vector to the bottom
	private float[][][] content; 
	public Ray determineRay(CameraPosition position,int x,int y)
	{
		float xperc = (float)x/(float)_xmax;
		float yperc = (float)y/(float)_ymax;
		float [] target= add(add(_o,multiply(_vy, yperc)),multiply(_vx, xperc));
		float[] direction = add(target,negate(position.getOrigin()));
		target[3]=1;
		direction[3]=1;
		return new SimpleRay(position.getOrigin(),direction,1,_source,arI(x,y));
	}
	public float[] getColor(int x,int y)
	{
		return content[x][y];
	}
	public void color(int i, int j, float[] color) {
		content[i][j]=cloo(color);
	}
	public int[] xy() {
		return arI(_xmax,_ymax);
	}
	public float[][][] getView() {
		return content;
	}
}
